package ai;

/**
 * 棋子类，为博弈树保存属性.
 *
 * @author 任禹名
 */
public class ChessNode implements Comparable<ChessNode> {

    private int x;//位置
    private int y;
    private int player;//玩家(颜色),如果为0则代表没有棋子

    private int offense;//攻击分
    private int defence;//防守分
    private int sum;//总分

    private StringBuffer buffer = new StringBuffer();

    @Override
    public String toString() {
        return "ChessNode [x=" + x + ", y=" + y + ", player=" + player + ", offense="
                + offense + ", defence=" + defence + ", sum=" + sum + "]";
    }

    public void setOffense(int offense) {
        this.offense = offense;
    }

    public void setDefence(int defence) {
        this.defence = defence;
    }

    public int getSum() {
        return sum;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }

    /**
     * 构造方法，设置棋子位置与玩家.
     *
     * @param x
     * @param y
     * @param player
     */
    public ChessNode(int x, int y, int player) {
        super();
        this.x = x;
        this.y = y;
        this.player = player;
    }

    public int getPlayer() {
        return player;
    }

    public void setPlayer(int player) {
        this.player = player;
    }


    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    /**
     * 重写比较方法,按总分比较.
     * @param chessNode
     * @return
     */
    public int compareTo(ChessNode chessNode) {//对棋子的总得分进行排序

        if (this.sum > chessNode.sum) {
            return -1;
        } else if (this.sum < chessNode.sum) {
            return 1;
        } else
            return 0;
    }

    public StringBuffer getBuffer() {
        return buffer;
    }


}
